import { reactive, ref } from "vue";
import type { ClTabsItem } from "@/uni_modules/cool-ui";
import { useUi } from "@/uni_modules/cool-ui";
import { usePager } from "@/cool";
export default function InitHook() {
	const activeKey = ref<string>("1");
	const tabList = ref<ClTabsItem[]>([
		{
			label: "棋牌娱乐",
			value: "1"
		},
		{
			label: "台球竞技",
			value: "2"
		},
		{
			label: "智慧KTV",
			value: "3"
		}
	]);
	const searchForm = reactive<Base.CommonData>({
		keyword: "",
		city: "深圳市",
		cityId: 4
	});
	const listViewRef = ref<ClListViewComponentPublicInstance | null>(null);
	const ui = useUi();
	let id = 1;
	const { refresh, list, listView, loading, loadMore } = usePager((params, { render }) => {
		// 模拟请求
		setTimeout(() => {
			render({
				list: [
					{
						id: id++,
						title: "春日樱花盛开时节，粉色花瓣如诗如画般飘洒",
						image: "https://unix.cool-js.com/images/demo/1.jpg"
					},
					{
						id: id++,
						title: "夕阳西下的海滩边，金色阳光温柔地洒在波光粼粼的海面上，构成令人心旷神怡的日落美景",
						image: "https://unix.cool-js.com/images/demo/2.jpg"
					},
					{
						id: id++,
						title: "寒冬腊月时分，洁白雪花纷纷扬扬地覆盖着整个世界，感受冬日的宁静与美好",
						image: "https://unix.cool-js.com/images/demo/3.jpg"
					}
				],
				pagination: {
					page: params["page"],
					size: params["size"],
					total: 100
				}
			});

			ui.hideLoading();
		}, 1000);
	});

	async function onPull() {
		await refresh({ page: 1 });
		listViewRef.value!.stopRefresh();
	}

	return {
		activeKey,
		tabList,
		searchForm,
		listView,
		list,
		loading,
		onPull,
		loadMore,
		refresh,
		ui
	};
}
